<?php

namespace App\Http\Middleware;

use Closure;
use Nette\Mail\Message;
use Nette\Mail\SendmailMailer;
use Nette\Mail\SmtpMailer;

class EmailMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // return $next($request);
        $rs=$next($request);        
        // echo 'email';
        // $request->user()->email;
        if($request->user()){

            $mail=new Message;
            $mail->setFrom('abing <176490815@163.com>')
                ->addTo($request->user()->email)
                ->setSubject('欢迎加入ONE影视联盟')
                ->setBody('欢迎加入ONE影视联盟，您的支持将是我们以后的动力!');

            $mailer =new SmtpMailer(array(
                    'host'=>'smtp.163.com',
                    'username'=>'176490815',
                    'password'=>'ABC123@' 
                    ));
            $mailer->send($mail);
        }

        return $rs;

    }
}
